<template>
	<section>
		<!-- 约工 -->
		<el-col :span="16">
			<div class="user-group">
				<h3>用户管理</h3>
				<!-- 输入框 -->
				<el-form :inline="true" style="margin-top:10px">
					<el-row>
			        	<!-- <el-col :span="12"> -->
			        		<el-form-item label="VIP等级：" :label-width="formLabelWidth2">
				            	<el-select v-model="vipId" placeholder="" clearable>
					              <!-- <el-option label="--请选择--" value=""></el-option> -->
					              <el-option label="VIP1" value="1"></el-option>
					              <el-option label="VIP2" value="2"></el-option>
					              <el-option label="VIP3" value="3"></el-option>
					              <el-option label="VIP4" value="4"></el-option>
					              <el-option label="VIP5" value="5"></el-option>
					              <el-option label="VIP6" value="6"></el-option>
				            	</el-select>
			          		</el-form-item>
			        	<!-- </el-col> -->
			        	<!-- <el-col :span="12"> -->
							<el-form-item label="部门：" :label-width="formLabelWidth2">
								<BelongTeam size="" @changes="getSelectDepart" style="width:90%" class="belongTeam"></BelongTeam>
					            <!-- <el-input
					            placeholder="请选择"
					            v-model="treeSelect.depart"
					            readonly="readonly"
					            ref="depart"
					            :value="treeSelect.departId"
					            @click.native="isShow=!isShow">
					          </el-input>
					          <el-tree
					            v-show="isShow"
					            class="box-tree"
					            node-key="id"
					            empty-text="暂无数据"
					            :data="treeSelect.regions"
					            :props="treeSelect.props"
					            :load="loadNode"
					            :expand-on-click-node="false"
					            lazy
					            @node-click="handleNodeClick">
					          </el-tree> -->
					          </el-form-item>
			        	<!-- </el-col> -->
			        </el-row>
			        <el-row>
			        	<!-- <el-col :span="12">				         -->
				          <el-form-item label="用户名：" class="item-small-size" :label-width="formLabelWidth2" style="margin-right:35px">
				            <el-input v-model="userName" placeholder="" class="small-size"></el-input>
				          </el-form-item>
				        <!-- </el-col> -->
				        <!-- <el-col :span="12">	 -->
				          <el-form-item label="真实姓名：" class="item-small-size" :label-width="formLabelWidth2">
				            <el-input v-model="realName" placeholder="" class="small-size"></el-input>
				          </el-form-item>
				        <!-- </el-col> -->
			        </el-row>
					<!-- 操作按钮 -->
					<div class="btn-group">
						<el-button type="primary" size="small" icon="plus" @click="handleAdd()">用户录入</el-button>
						<!-- <el-button type="primary" size="small" icon="edit" @click="handleEdit()" >用户编辑</el-button> -->
					    <el-button type="primary" size="small" icon="edit" @click="handleResetpw()">重置密码</el-button>
						<!-- <el-button type="primary" size="small" icon="edit" @click="handleLock()" >锁定用户</el-button>
						<el-button type="primary" size="small" icon="edit" @click="handleActive()">激活用户</el-button> -->
						<el-button type="primary" size="small" icon="edit" @click="unlockAccount()" >解锁用户</el-button>
						<el-button type="primary" size="small" icon="circle-close" @click="handleReset()" style="float:right">重置</el-button>
						<el-button type="primary" size="small" icon="search" @click="handleSerch()" style="float:right;">查询</el-button>
					</div>
				</el-form>
				<!--列表-->
				<el-table :data="depTableData" border height="460" 
					v-loading="listLoading" @current-change="handleSelectionChange" highlight-current-row>
				    <el-table-column type="index" width="55"></el-table-column>
				    <el-table-column prop="userName" label="用户名" width="130"></el-table-column>
				    <el-table-column prop="departName" label="部门" min-width="110"></el-table-column>
				    <!-- <el-table-column prop="deptName" label="单位名" width="125"></el-table-column> -->
				    <el-table-column prop="realName" label="真实姓名" width="110"></el-table-column>
				    <!-- <el-table-column prop="vipId" label="VIP等级" width="125"></el-table-column> -->
				    <!-- <el-table-column prop="email" label="邮箱" width="110"></el-table-column> -->
				    <el-table-column prop="mobilePhone" label="移动电话" width="125"></el-table-column>
				    <!-- <el-table-column prop="officePhone" label="办公电话" width="110"></el-table-column> -->
				    <el-table-column prop="status" label="状态" width="110"></el-table-column>
				    <el-table-column label="操作" fixed="right" width="250">
				      <template scope="scope" >
				        <el-button size="small" type="danger"
				          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
				        <el-button size="small" @click="handleEdit(scope.$index, scope.row)">用户编辑</el-button>
				        <el-button size="small" @click="handleManage(scope.$index, scope.row)">角色设置</el-button>
				        
				      </template>
				    </el-table-column>
				</el-table>
				<!--工具条-->
				<el-col :span="24" class="toolbar">
					<el-pagination
					 small
					 @size-change="handleSizeChange"
				     @current-change="handleCurrentChange"
				     :current-page="currentPage[0]"
				     :page-sizes="[10, 20, 30]"
				     :page-size="size[0]"
				     layout="total, sizes, prev, pager, next, jumper"
				     :total="totals[0]" 
					 style="float:right;">
      				</el-pagination>
				</el-col>
			</div>
		</el-col>

		<!--编辑/录入/查看界面-->
		<el-dialog :title="dialog.dialogTitle" v-model="editFormVisible" :close-on-click-modal="false" @close="isEdit=false">
			<el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm" class="departMentiput">
				<el-col :span="12">
					<el-form-item label="用户名:" prop="userName" required :label-width="formLabelWidth">
						<el-input v-model="editForm.userName" class="short-size" :disabled="isUseredit" placeholder="用户名范围在2~50位字符"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="真实姓名:" prop="realName" required :label-width="formLabelWidth">
						<el-input v-model="editForm.realName" class="short-size" :disabled="isEdit" placeholder="填写个人真实姓名"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="密码:" prop="password" required :label-width="formLabelWidth" v-if="pwShow" >
						<el-input v-model="editForm.password" class="short-size" :disabled="isEdit" placeholder="请输入包含大小写字母数字,8-30位"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="重复密码:" prop="repassword" required :label-width="formLabelWidth" v-if="pwShow">
						<el-input  v-model="editForm.repassword" class="short-size" :disabled="isEdit" placeholder="重复个人密码"></el-input>
					</el-form-item>
				</el-col>
				<!-- <el-row> -->
				<el-col :span="12">
					<el-form-item label="部门："  prop="departName" required :label-width="formLabelWidth" >
						<!-- <el-input v-show="isEdit" v-model="editForm.departId" disabled class="short-size" placeholder="请选择部门"></el-input> -->
						 <el-input
						 	placeholder="请选择"
						 	v-model="editForm.departName"
						 	readonly="readonly"
						 	ref="depart1"
						 	:value="editForm.departId"
						 	@click.native="isShow1=!isShow1">
						</el-input>
						<el-tree
						 	v-show="isShow1"
						 	class="box-tree"
						 	node-key="id"
						 	ref="depart1"
						 	empty-text="暂无数据"
						 	:data="department.regions"
						 	:props="department.props"
						 	:load="loadNode"
						 	:expand-on-click-node="false"
						 	lazy
						 	@node-click="handleNodeClick1">
						</el-tree>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="兼职部门：" :label-width="formLabelWidth" prop="partDept" v-show="partShow2">
						<!-- <el-input v-show="isEdit" v-model="editForm.partDept" disabled class="short-size"></el-input> -->
						 <el-input
						 	placeholder="请选择"
						 	v-model="editForm.partDeptName"
						 	readonly="readonly"
						 	:value="editForm.partDept"
						 	@click.native="isShow2=!isShow2">
						</el-input>
						<el-tree
						 	v-show="isShow2"
						 	class="box-tree"
						 	node-key="id"
						 	empty-text="暂无数据"
						 	:data="departments2.regions"
						 	:props="departments2.props"
						 	:load="loadNode2"
						 	:expand-on-click-node="false"
						 	lazy
						 	show-checkbox
						 	check-strictly
						 	@node-click="handleNodeClick2"
	  						@check-change="handleCheckChange">
						</el-tree>						
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="兼职部门：" :label-width="formLabelWidth" prop="partDept" v-show="partShow3">
						<el-input
						 	placeholder="请选择"
						 	v-model="editForm.partDeptName"
						 	readonly="readonly"
						 	:value="editForm.partDept"
						 	@click.native="clean">
						</el-input>
						<el-tree
						 	v-show="isShow3"
						 	class="box-tree"
						 	node-key="id"
						 	empty-text="暂无数据"
						 	:data="departments.regions"
						 	:props="departments.props"
						 	:load="loadNode3"
						 	:expand-on-click-node="false"
						 	lazy
						 	show-checkbox
						 	check-strictly
						 	:default-expanded-keys="expanded"
				 			:default-checked-keys="checked"
						 	@node-click="handleNodeClick3"
	  						@check-change="handleCheckChange3">
						</el-tree>
					</el-form-item>
				</el-col>
				<!-- </el-row> -->
				<el-col :span="12">
					<el-form-item label="职务:" prop="job" :label-width="formLabelWidth">
						<el-input v-model="editForm.job" class="short-size" :disabled="isEdit"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="兼职职务:" prop="partJob" :label-width="formLabelWidth">
						<el-input v-model="editForm.partJob" class="short-size" :disabled="isEdit"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
				<el-form-item label="手机号码:" prop="mobilePhone"  :label-width="formLabelWidth">
					<el-input v-model="editForm.mobilePhone" class="short-size" :disabled="isEdit"></el-input>
				</el-form-item>
				</el-col>
				<el-col :span="12">
				<el-form-item label="办公电话:" prop="officePhone" :label-width="formLabelWidth">
					<el-input v-model="editForm.officePhone" class="short-size" :disabled="isEdit"></el-input>
				</el-form-item>
				</el-col>
				<el-col :span="12">
				<el-form-item label="内线电话:" prop="interPhone" :label-width="formLabelWidth">
					<el-input v-model="editForm.interPhone" class="short-size" :disabled="isEdit"></el-input>
				</el-form-item>
				</el-col>
				<el-col :span="12">
				<el-form-item label="传真:" prop="fax" :label-width="formLabelWidth">
					<el-input v-model="editForm.fax" class="short-size" :disabled="isEdit"></el-input>
				</el-form-item>
				</el-col>
				<el-col :span="12">
				<el-form-item label="微信号:" prop="wxId" :label-width="formLabelWidth">
					<el-input v-model="editForm.wxId" class="short-size" :disabled="isEdit"></el-input>
				</el-form-item>
				</el-col>
				<el-col :span="12">
				<el-form-item label="康拓普用户id:" prop="ktpUserId" :label-width="formLabelWidth">
					<el-input v-model="editForm.ktpUserId" class="short-size" :disabled="isEdit"></el-input>
				</el-form-item>
				</el-col>
				<el-col :span="12">
				<el-form-item label="位置:" prop="location" :label-width="formLabelWidth">
					<el-input v-model="editForm.location" class="short-size" :disabled="isEdit"></el-input>
				</el-form-item>
				</el-col>
				<el-col :span="12">
				<el-form-item label="常用邮箱:" prop="email" :label-width="formLabelWidth">
					<el-input v-model="editForm.email" class="short-size" :disabled="isEdit"></el-input>
				</el-form-item>
				</el-col>
				<el-col :span="12">
				<el-form-item label="VIP等级：" prop="vipId" :label-width="formLabelWidth">
				     <el-select v-model="editForm.vipId" placeholder="" >
					    
					    <el-option label="VIP1" value="1"></el-option>
					    <el-option label="VIP2" value="2"></el-option>
					    <el-option label="VIP3" value="3"></el-option>
					    <el-option label="VIP4" value="4"></el-option>
					    <el-option label="VIP5" value="5"></el-option>
					    <el-option label="VIP6" value="6"></el-option>
				     </el-select>
			    </el-form-item>
				</el-col>
				
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">关闭</el-button>
				<el-button type="primary" @click.native="editSubmit('editForm')" v-show="!isEdit">确定</el-button>
			</div>
		</el-dialog>
		
		<!-- 重置密码 -->
		<div class="userManagePwDialog">
			<el-dialog :title="dialog.dialogTitle" v-model="resetDialog" :close-on-click-modal="false" @close="isEdit=false">	
			<el-form :model="resetForm" label-width="80px" :rules="editFormRules2" ref="resetForm">
				<el-form-item label="登陆名:" prop="personName" required :label-width="formLabelWidth">
					<el-input v-model="resetForm.personName" class="short-size" disabled></el-input>
				</el-form-item>
				<el-form-item label="中文名:" prop="personPhone" required :label-width="formLabelWidth">
					<el-input v-model="resetForm.personPhone" class="short-size" disabled></el-input>
				</el-form-item>
				<el-form-item label="新密码:" prop="password" required :label-width="formLabelWidth">
					<el-input v-model="resetForm.password" class="short-size" :disabled="isEdit"></el-input>
				</el-form-item>
			</el-form>
				<div slot="footer" class="dialog-footer">
					<el-button @click.native="resetDialog = false">关闭</el-button>
					<el-button type="primary" @click.native="resetSubmit('resetForm')" v-show="!isEdit">确定</el-button>
				</div>
			</el-dialog>
		</div>

		<!-- 人员 -->
		<el-col :span="8">		
			<div class="user-group" v-loading="personLoading">
				<h3>{{personRealName}}：当前角色</h3>
				<div v-if="userModule">
					<p>用户角色</p>
					<!--工具条-->
					<el-col :span="24">
						<el-form :inline="true" :model="filters">
							<el-col :span="12">
								
								<el-form-item>
									<el-button type="primary" size="small" icon="plus" @click="handleAdd2()">添加角色</el-button>
								</el-form-item>
							</el-col>
							
						</el-form>
					</el-col>
					<!-- 人员列表 -->
					<el-table :data="personTableData" border height="444" style="width: 100%" @current-change="handleSelectionChange2" highlight-current-row>
					    <el-table-column type="index" width="55"></el-table-column>
					    <el-table-column prop="roleName" label="角色名称" width="130"></el-table-column>
					    <el-table-column prop="departName" label="部门名称" width="130"></el-table-column>
					    <el-table-column label="操作" fixed="right">
					      <template scope="scope">
					        <el-button size="small" type="danger"
					          @click="personDelete(scope.$index, scope.row)">删除</el-button>
					      </template>
					    </el-table-column>
					</el-table>
					
					<!-- 添加/编辑/查看人员界面 -->
					 <el-dialog :title="dialog.dialogTitle" v-model="editPersonDialog" :close-on-click-modal="false" @close="isEdit=false">	
					  	
						<el-form :inline="true" :model="editpersonForm">
			              <el-row>
			                <el-col :span="12">               
			                  <el-form-item label="角色编码：">
			                    <el-input v-model="roleCode" placeholder="" ></el-input>
			                  </el-form-item>
			                </el-col>
			                <el-col :span="12"> 
			                  <el-form-item label="角色名称：">
			                    <el-input v-model="roleName" placeholder="" ></el-input>
			                  </el-form-item>
			                </el-col>
			              </el-row>
				           <!-- 操作按钮 -->
				          <div class="btn-group" >
				            <el-button type="primary" size="small" icon="circle-close" @click="handleReset2()" style="margin-left:10px;float:right">重置</el-button>
				            <el-button type="primary" size="small" icon="search" @click="handleSerch2()" style="float:right;margin-bottom: 5px;">查询</el-button>
				            
				          </div>
    
					      <el-table
					      :data="table"
					      border
					      tooltip-effect="dark"
					      style="width: 100%"
					      v-loading="roleLoading"
					      @selection-change="handleSelection">
					          <el-table-column type="selection" width="55" >
					          </el-table-column>
					          <el-table-column type="index" width="60">
					          </el-table-column>
					          <el-table-column prop="roleCode" label="角色编码" min-width="140" sortable>
					          </el-table-column>
					          <el-table-column prop="roleName" label="角色名称" min-width="180" sortable>
					          </el-table-column>
					          <el-table-column prop="status" label="状态" min-width="100" sortable>
					          </el-table-column>
					      </el-table>
					      <!-- 工具条 -->
					        <el-col :span="24" class="toolbar">
					          <el-pagination
					           small
					           @size-change="handleSizeChange3"
					             @current-change="handleCurrentChange3"
					             :current-page="currentPage[1]"
					             :page-sizes="[10, 20, 30]"
					             :page-size="size[1]"
					             layout="total, sizes, prev, pager, next, jumper"
					             :total="totals[1]" 
					           style="float:right;">
					              </el-pagination>
					        </el-col>
					    </el-form>
					  	<div slot="footer" class="dialog-footer">
								<!-- <el-input v-show="isEdit" v-model="editForm.departId" disabled class="short-size" placeholder="请选择部门"></el-input> -->
								 <!-- <el-input
								 	placeholder="请选择"
								 	v-model="roleDepart.departName"
								 	readonly="readonly"
								 	ref="depart1"
								 	:value="roleDepart.departId"
								 	@click.native="roleDeptShow=!roleDeptShow">
								</el-input>
								<el-tree
								 	v-show="roleDeptShow"
								 	class="box-tree"
								 	node-key="id"
								 	ref="depart1"
								 	empty-text="暂无数据"
								 	:data="department.regions"
								 	:props="department.props"
								 	:load="loadNode"
								 	:expand-on-click-node="false"
								 	lazy
								 	@node-click="handleNodeClickRole">
								</el-tree> -->
							<el-button @click.native="editPersonDialog = false">关闭</el-button>
							<el-button type="primary" @click.native="editPersonSubmit()" v-show="!isEdit">确定</el-button>
						</div>
					</el-dialog>  
				</div>
			</div>
		</el-col>
	</section>
</template>
<script>
    import BelongTeam from 'components/belongTeam'
	import { userManageList,roleList,departList,addUserMa,roleAddList,editUserMa,resetPw,delUserMa,delRole,addUserRole,lockUser,getUserData,getOtherDepart,unlockUser,getDepartZtree} from '../../api/system'
	// import { getOtherDepart,userManageList,roleList,departList,addUserMa,roleAddList,editUserMa,resetPw,delUserMa,delRole,addUserRole,lockUser,getUserData} from '../../api/system'getOtherDepart
	export default {
    data() {

      	//用户录入判断两次密码是否相同
      	var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.editForm.password) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
        };
      return {
		roleDepart:{},
      	roleDeptShow:false,
      	// 检索输入框
      	vipId:'',
      	userName:'',
      	realName:'',
      	status:'',//状态
      	treeSelect:{
        depart:'',
        departId:'',
        regions: [],
        props: {
          label: 'text',
          children: 'id'
        }
       },
      	
      	sels:[],
      	currentRow:[],
      	
      	depTableData:[],
      	formLabelWidth:'110px',
      	formLabelWidth2:'100px',
      	editFormVisible:false,
      	listLoading: false,
      	roleLoading:false,
      	isEdit: false,
      	isUseredit:false,
		isShow: false,
		isShow1: false,
		isShow2: false,
		isShow3: false,
		partShow2: false,
		partShow3: false,
		pwShow:true,
		checkedData:'',
		expanded:[],
		checked:[],
		// 弹框标题
		dialog: {
			dialogType: 0,
			dialogTitle: ''
		},
      	//编辑界面数据
      	editpersonForm:{

      	},

		editForm:{
			// departments:[],
			partDeptName:'',
			partDept:'',
			vipId:''
		},
		partDeptName:'',
		partDept:'',
		department:{
					regions: [],
			        props: {
			          label: 'name',
			          children: 'id'
			        }
				},
		departments2:{
			regions: [],
	        props: {
	          label: 'name',
	          children: 'id'
	        }
		},
		departments:{
					regions: [],
			        props: {
			          label: 'name',
			          children: 'id'
			        }
				},
		editFormRules:{
			userName:[{ required: true, message: '请输入用户名', trigger: 'blur' },
					  { min: 2, max: 50, message: '用户名范围在2~50位字符', trigger: 'blur' }],

			realName:[{ required: true, message: '请输入真实姓名', trigger: 'blur' }],

			password:[{ required: true, message: '请输入密码', trigger: 'blur' },
					  { min: 8, max: 30, message: '包含大小写字母数字8-30位', trigger: 'blur' }],
			departName:[{ required: true, message: '请选择部门', trigger: 'change' }],
			repassword:[{ required: true, validator: validatePass2, trigger: 'blur' }],
			
		},
		editFormRules2:{},
		
		editPersonDialog:false,
		
		resetDialog:false,
		resetForm:{},
		// lockDialog:false,
		// activeDialog:false,

      	totals: [0,0],
		page: [1,1],
		size: [10,10],
		currentPage: [1,1],

		personLoading:false,
		personRealName:'',
		
		personTableData:[],
		//用户列表数据
		userModule: false,
		filters:{
			type:'personName',
			search:'',
			userId: ''
		},
		table:[],
		
		roleCode:'',
		roleName:'',	

		saveId:{id:'',userName:''},
		first:1
      }
  },
  components: {
		BelongTeam
	},
  methods:{
  	//点击节点选中节点数据
      handleNodeClick(data,node){
        this.treeSelect.departId = data.id;
        this.treeSelect.depart = data.name;
        this.isShow=!this.isShow;
      },
      handleNodeClick1(data,node){
      	this.editForm.departId = data.id;
        this.editForm.departName = data.name;
        this.isShow1=!this.isShow1;
      },
      handleNodeClick2(data,node){
        this.isShow2=!this.isShow2;
      },
      handleNodeClick3(data,node){
        this.isShow3=!this.isShow3;
      },
      getSelectDepart(id){
        this.treeSelect.departId=id;
      },
  	//加载树结点
      loadNode(node, resolve) {
        if (node.level === 0) {
	        getDepartZtree().then(res => {
	          let teamData = res.obj;
	          return resolve(teamData);
	        });
	      }else{
	        var hasChild;
	        if (node.data.isParent) {
	          hasChild = true;
	        } else{
	          hasChild = false;
	        }
	      }
	      var children;
	      if (hasChild) {
	        getDepartZtree({id:node.data.id}).then(res => {
	          children = res.obj;
	          resolve(children);
	        });
	      } else {
	        children = [];
	        resolve(children);
	      }
        },

       loadNode2(node, resolve) {       	
	    	var para={id:node.data.id};
	    	console.log(para);
	    	getDepartZtree(para).then(res => {   
		        return resolve(res.obj);
		        var data;  
		        if(res.obj.length){
		            data=res.obj;
		          }
		          else{data=[];}
		          resolve(data);
		      });
	    },
    loadNode3(node, resolve){
	    	var para={};
	    	if(node.data.id){
				para.id = node.data.id;
			}else{
				para.id = 0;
			}
	    	getDepartZtree(para).then(res => {   
		        return resolve(res.obj);
		        var data;  
		        if(res.obj.length){
		            data=res.obj;
		          }
		          else{data=[];}
		          resolve(data);
		      });
    },
    // 复选树
    handleCheckChange(data, checked, indeterminate){
    		if(checked){
    			if(this.editForm.partDeptName==""){
    				this.editForm.partDeptName = data.name;
	    			this.editForm.partDept = data.id;
    			}else{
    				this.editForm.partDeptName += ',' + data.name ;
	    			this.editForm.partDept += ',' + data.id;
    			}
	    	}else{
	    		if(this.editForm.partDeptName.indexOf(',')>-1){	   			
		    		this.editForm.partDeptName = this.editForm.partDeptName.replace(','+data.name,'');
		    		this.editForm.partDeptName = this.editForm.partDeptName.replace(data.name+',','');
		    		this.editForm.partDept = this.editForm.partDept.replace(data.id+',','');
		    		this.editForm.partDept = this.editForm.partDept.replace(','+data.id,'');
	    		}else{
	    			this.editForm.partDeptName = '';
	    			this.editForm.partDept = '';
	    		}
	    	}
	    	console.log(this.editForm.partDeptName);
	    	console.log(this.editForm.partDept);
    },
    handleCheckChange3(data, checked, indeterminate){
		if(checked){
			if(this.editForm.partDeptName==""){
				this.editForm.partDeptName = data.name;
    			this.editForm.partDept = data.id;
			}else{
				if(this.editForm.partDeptName.charAt(this.editForm.partDeptName.length - 1)==','){					
		    		this.editForm.partDeptName = this.editForm.partDeptName.substring(0, this.editForm.partDeptName.lastIndexOf(','));				
		    		// this.editForm.partDept = this.editForm.partDept.substring(0,this.editForm.partDept.lastIndexOf(','));
		    		this.editForm.partDeptName += ',' + data.name ;
    				this.editForm.partDept += ',' + data.id;
				}else{
					this.editForm.partDeptName += ',' + data.name ;
    				this.editForm.partDept += ',' + data.id;
				}								
			}
    	}else{
    		if(this.editForm.partDeptName.indexOf(',')>-1){	   			
	    		this.editForm.partDeptName = this.editForm.partDeptName.replace(','+data.name,'');
	    		this.editForm.partDeptName = this.editForm.partDeptName.replace(data.name+',','');
	    		this.editForm.partDept = this.editForm.partDept.replace(data.id+',','');
	    		this.editForm.partDept = this.editForm.partDept.replace(','+data.id,'');
    		}else{
    			this.editForm.partDeptName = '';
    			this.editForm.partDept = '';
    		}
    	}
    	console.log(this.editForm.partDeptName);
    	console.log(this.editForm.partDept);	    		    	
    },

  	//获得表格选中的列的数据
	handleSelectionChange(val){
		// console.log(val);
		this.currentRow1 = val;
	},
	handleSelectionChange2(val){
		this.currentRow2 = val;
		// console.log(this.sels.length);
	},
	handleSelection(val){
		this.sels = val;
	},
	// 查询
	handleSerch(){
		
		let userParams = {
			rows: this.size[0],
			page: this.currentPage[0],
			vipId:this.vipId,
			departName:this.treeSelect.departId,
			userName:this.userName,
			realName:this.realName,
		};	
		userParams.field = "departName,email,id,mobilePhone,officePhone,realName,state,status,userName,vipId";	       
			this.listLoading = true;
        	userManageList(userParams).then(res => {

        		for (var i = res.rows.length - 1; i >= 0; i--) {
							if(res.rows[i].status==1){res.rows[i].status="正常"}
						}
        		// console.log(res);
				this.totals[0] = Number(res.total);
				this.depTableData = res.rows;
				// console.log(this.depTableData);
				this.listLoading = false;
			});
      
	},
	// 重置
	handleReset(){
		this.treeSelect.departId='';
		this.treeSelect.depart='';
		this.vipId='';
		this.userName='';
		this.realName='';
		this.getDepts(0);

	},
	handleSerch2(){
		let para = {
            page: this.currentPage[1],
            rows: this.size[1],
            field:"id,roleCode,roleName",
            userId: this.filters.userId,
            roleCode:this.roleCode,
            roleName:this.roleName,
          };
        this.roleLoading = true;
        roleAddList(para).then((res) => {         
            this.table = res.rows;
            this.totals[1] = Number(res.total);
            this.roleLoading = false;
        });
	},
	handleReset2(){
		this.roleCode=null;
        this.roleName=null;
        this.getDepts(1);
	},
	// 重置密码
	handleResetpw(){
		let selsSum = this.currentRow1;
		if(selsSum ==null){
			this.$alert('请选择行！','错误',{ type: 'error'});
		}else{
			this.resetDialog=true;
			this.dialog.dialogTitle="重置密码";
			this.resetForm.personName=this.currentRow1.userName;
			this.resetForm.personPhone=this.currentRow1.realName;
		};
	},
	resetSubmit(resetForm){
		
		
		var para={
			id:this.currentRow1.id,
			userResetPassword:true,
			password:this.resetForm.password,
			

		};
		// console.log(para);
		resetPw(para);
		this.resetDialog=false;
	},
	// 用户锁定
	/*handleLock(){
		let selsSum = this.currentRow1;
		if(selsSum ==null){
			this.$alert('请选择行！','错误',{ type: 'error'});
		}else{
			this.$confirm('确认锁定选定用户？', '提示', {
	          type: 'warning'
	        }).then(() => { 
	        	var para={
					lock:'',
					lockvalue:0,
					id:this.currentRow1.id,
				}
				this.saveId.id=para.id;
				this.saveId.userName=this.currentRow1.userName;
				lockUser(para).then(()=>{
					var params={
						userName:this.currentRow1.userName,
						realName:this.currentRow1.realName,
						vipId:this.currentRow1.vipId,
						departName:this.currentRow1.departName
					};
					params.field = "departName,email,id,mobilePhone,officePhone,realName,state,status,userName,vipId";
					// this.listLoading = true;
			        userManageList(params).then(res => {
						this.totals[0] = Number(res.total);
						this.depTableData = res.rows;
					});
				});
				
		    }).catch(() => {

	        });
		};
	},*/
	// 激活用户
	/*handleActive(){
		
		this.$confirm('确认激活选定用户？', '提示', {
	          type: 'warning'
	        }).then(() => { 
	        	var para={
					lock:'',
					lockvalue:1,
					id:this.saveId.id,
				};
				lockUser(para).then(()=>{
					var params={
						userName:this.saveId.userName,
					};
					params.field = "departName,email,id,mobilePhone,officePhone,realName,state,status,userName,vipId";
			        userManageList(params).then(res => {
						this.totals[0] = Number(res.total);
						this.depTableData = res.rows;
						this.listLoading = false;
					});
			    
				});
			}).catch(() => {

			    });

				
	},*/
	//重置用户
	unlockAccount(){
		let selsSum = this.currentRow1;
		if(selsSum ==null){
			this.$alert('请选择行！','错误',{ type: 'error'});
		}else{
			this.$confirm('确认解锁选定用户？', '提示', {
	          type: 'warning'
	        }).then(() => {

	        var para={
					
					userId:this.currentRow1.id,
				}
				this.saveId.id=para.id;
				this.saveId.userName=this.currentRow1.userName;
				unlockUser(para).then(()=>{
					this.getDepts(0);
				});
				
		    }).catch(() => {

	        });
		

		}
	
},
	
	//加载列表数据
	getDepts(index,id){
		let userParams = {
			rows: this.size[index],
			page: this.currentPage[index]
		};

        		//单位列表数据
        		if(index==0){
					this.listLoading = true;
					// userParams.vipId=this.vipId,
					// userParams.departName=this.departName,
					// userParams.userName=this.userName,
					// userParams.realName=this.realName,
					userParams.field = "departName,email,id,mobilePhone,officePhone,realName,state,status,userName,vipId"
        			userManageList(userParams).then(res => {
        				console.log(res);
						this.totals[0] = Number(res.total);
						// console.log(res.rows.length);
						for (var i = res.rows.length - 1; i >= 0; i--) {
							if(res.rows[i].status==1){res.rows[i].status="正常"}
						}
						this.depTableData = res.rows;
						this.listLoading = false;
						// console.log(this.depTableData.id);
					});
        		}
        		//列表数据加载
        		else if(index==1){
        			this.roleLoading = true;
        			userParams.field = "id,roleCode,roleName";
        			userParams.userId = this.filters.userId;
					roleAddList(userParams).then(res => {
						// console.log(res);
						this.table = res.rows;
						this.totals[1] = Number(res.total);
						this.roleLoading = false;
					});
        		}
        		else if(index==2){
		          	getDepartZtree({}).then((res)=>{
		          		this.departments.regions=res.obj;
		          	});
		          	// alert(1);
	          	}
        		//人员列表数据加载
        		else {
        			this.userLoading = true;
        			userParams.userId = this.filters.userId;
        			userParams.field = "id,roleName";
					roleList(userParams).then(res => {
						this.personTableData = res;
						this.personLoading = false;
					});
        		}
        		
	},
	//单位列表切换列表页
	handleCurrentChange(val) {
		this.currentPage[0] = val;
		console.log(this.departName);
		if(this.vipId==null && this.departName==null && this.userName==null && this.realName==null){
          this.getDepts(0);
        }else{
          this.handleSerch();
        };
	},
	//单位列表切换显示条数
	handleSizeChange(val){
		this.size[0] = val;
		if(this.vipId==null && this.departName==null && this.userName==null && this.realName==null){
          this.getDepts(0);
        }else{
          this.handleSerch();
        };
	},
	
	handleCurrentChange3(val){
		this.currentPage[1] = val;
		if(this.roleCode==null && this.roleName==null){
          this.getDepts(1);
        }else{
          this.handleSerch2();
        };
	},
	handleSizeChange3(val){
		this.size[1] = val;
		if(this.roleCode==null && this.roleName==null){
          this.getDepts(1);
        }else{
          this.handleSerch2();
        };
	},

  	//显示录入界面
	handleAdd(){
		this.pwShow = true;
		this.dialog.dialogTitle = '用户录入';
		this.dialog.dialogType = 0;
		this.partShow3 = false;
		this.isUseredit=false;
		this.isShow2 = false;
		this.partShow2 = true;
		this.getDepts(2);
		this.editForm={
			userName:'',
			realName:'',
			password:'',
			repassword:'',
			departName:'',
			departId:'',
			partDept:'',
			partDeptName:'',
			job:'',
			partJob:'',
			mobilePhone:'',
			officePhone:'',
			interPhone:'',
			fax:'',
			wxId:'',
			ktpUserId:'',
			location:'',
			email:'',
			vipId:'',
			id:'',
		};
		
		this.editFormVisible = true;
	},
	//显示编辑界面
	handleEdit(index,row) {
		this.pwShow = false;
		this.partShow2 = false;
		this.isShow3 = false;		
		this.partShow3 = true;
		this.isUseredit=true;

		this.dialog.dialogTitle = '用户编辑';
		this.dialog.dialogType = 1;
		this.editFormVisible = true;
		/*delete this.editFormRules.password;
		delete this.editFormRules.repassword;*/
		this.checked =[];
		getUserData({id:row.id}).then((res)=>{

			if(this.first==1){
				this.editForm.partDept=res.obj.partDept;
				this.editForm.partDeptName=res.obj.partDeptName;
			}
			// this.editForm = res.obj;		
			this.checkedData = res.obj.partDept;
			this.editForm.userName=res.obj.userName;
			this.editForm.realName=res.obj.realName;
			this.editForm.departName=res.obj.departName;
			this.editForm.departId=res.obj.departId;
			/*this.editForm.partDept=res.obj.partDept;
			this.editForm.partDeptName=res.obj.partDeptName;*/
			this.editForm.job=res.obj.job;
			this.editForm.partJob=res.obj.partJob;
			this.editForm.mobilePhone=res.obj.mobilePhone;
			this.editForm.officePhone=res.obj.officePhone;
			this.editForm.interPhone=res.obj.interPhone;
			this.editForm.fax=res.obj.fax;
			this.editForm.wxId=res.obj.wxId;
			this.editForm.ktpUserId=res.obj.ktpUserId;
			this.editForm.location=res.obj.location;
			this.editForm.email=res.obj.email;
			this.editForm.vipId= res.obj.vipId;
			this.editForm.id=row.id;
			this.getDepts(2);
			if(res.obj.partDeptName==null || res.obj.partDeptName==undefined){
				this.editForm.partDept='';
				this.editForm.partDeptName='';
			}
			this.$nextTick(function () {
				if(this.checkedData){
					if(this.checkedData[this.checkedData.length-1]==',')
						this.checkedData=this.checkedData.substring(0,this.checkedData.length-1);
					this.checked = this.checkedData.split(",");
					console.log(this.checked);						
				}
			});				
			this.first++;
		});
		
	},
	clean(){
		this.isShow3=!this.isShow3;
		if(this.isShow3==true){
				// this.editForm.partDeptName='';
				// this.editForm.partDept='';
			}
	},
	//显示人员录入界面
	handleAdd2(){
		this.dialog.dialogTitle = '添加角色';
		this.dialog.dialogType = 0;
		this.getDepts(1);
		this.editPersonDialog = true;
	},
	handleNodeClickRole(data,node){
		this.roleDepart.departId = data.id;
        this.roleDepart.departName = data.text;
        this.roleDeptShow=!this.roleDeptShow;
	},
	//提交添加人员
	editPersonSubmit(){
		
		// console.log(this.sels);
		var para={
			departId:this.roleDepart.departId,
			departName:this.roleDepart.departName,
			userId:this.filters.userId,
			roleidstr:this.sels.map(item => item.id).toString(),
		}
		addUserRole(para).then(()=>{
			this.getDepts();
		});
		
		this.editPersonDialog = false;
		// console.log(this.editpersonForm);
	},	
	
  	//删除
	handleDelete(index, row) {
		this.$confirm('确认删除该记录吗?', '提示', {
			type: 'warning'
		}).then(() => {
			this.listLoading = true;
			let para = { 
				id: row.id,
				userName: row.userName,
				status:1
			 };
			delUserMa(para).then(()=>{
				this.getDepts(0);
			});
		});			
	},
	//用户录入/编辑保存提交
	editSubmit(editForm){
		this.$refs[editForm].validate((valid) => {

	        if (valid) {
	        	var formParams = this.editForm;
	        	// console.log(formParams);
	        	/*formParams.deptId = this.editForm;*/
	        	if(this.dialog.dialogType == 0){
	        		//录入提交
	        		
		        	addUserMa(formParams).then(()=>{
		        		this.getDepts(0);

		        	});
		        
			        this.editFormVisible = false;
	        	}else if(this.dialog.dialogType == 1){
	        		//编辑提交
	        		// this.editFormRules.password=[];
	        		// console.log(this.editFormRules);
	        		console.log(formParams);
	        		editUserMa(formParams).then(()=>{
		        		this.getDepts(0);
		        	});
	        		this.editFormVisible = false;
	        	}
	        }else {
	            console.log('error submit!!');
	            return false;
	        }
	    })
	},
	//单位人员管理
	handleManage(index, row){
		this.personLoading = true;
		this.filters.userId = row.id;
		this.personRealName = row.realName;
		// console.log(index);
		this.getDepts();
		this.userModule = true;
	},


	//删除用户
	personDelete(index,row){
		this.$confirm('确认删除该记录吗?', '提示', {
			type: 'warning'
		}).then(() => {
			this.personLoading = true;
			let para = { userId: row.userId,id: row.id };
			delRole(para).then(()=>{
				this.getDepts();
			});
			this.personLoading = false;
			
		});
		
	},		
	

  },
  activated:function(){
			this.getDepts(0);
		}
}
</script>
<style scoped lang="scss">
	.box-tree{
    position: absolute;
    overflow: auto;
    z-index: 100;
    width: 100%;
    max-height: 300px;
  }
	.user-group{
		border: 1px solid #bfcbd9;
		padding: 5px 10px;
		height: 730px;
		h3{
			line-height: 30px;
			border-bottom: 1px solid #eee;
		}
		p{
			margin: 0;
			padding-left: 10px;
		}
		.btn-group{
			margin-bottom: 10px;
		}
		.to-right{
			text-align: right;
		}
		.short-form{
			width: 35%;
		}
	}
	.short-size{
		width: 90%;
	}
	
	.toolbar{
		background: #eee;
	}
	.dialog-footer{
		padding-top:20px;
	}
</style>
